package cn.hl.hm.quartz;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import cn.hl.hm.constants.UploadConfig;
import cn.hl.hm.dao.RoadFeeMapper;
import cn.hl.hm.entity.RoadFee;
import cn.hl.hm.util.picRZ.PictureIdentify;
/**
 * 
 * @author 大和
 *
 */
@Component
public class PicReverseNumQuartz {
	
	@Autowired
	RoadFeeMapper roadFeeMapper;
	@Autowired
	@Qualifier("uploadConfig")
	private UploadConfig uploadConfig;
	private static final Logger logger = LoggerFactory.getLogger(PicReverseNumQuartz.class);

	//@Scheduled(cron = "0 */6 * * * ?") //每6分钟
	public void addRVP() {
		RoadFee roadFee = new RoadFee();
		roadFee.setPageId(0);
		roadFee.setPageCount(1000);
		String ctxPath = uploadConfig.getShortUrl();
		List<RoadFee> selectNewOrder = roadFeeMapper.selectNewOrder(roadFee);
		int i = 0;
		int j = 0;
		int z = 0;

		if(selectNewOrder!=null&&selectNewOrder.size()>0){
			for (RoadFee order : selectNewOrder) {
				String plateNumberPic = order.getPlateNumberPic();
				String plateNumber = order.getPlateNumber();
					if(StringUtils.isBlank(plateNumber)){
						if(StringUtils.isNotBlank(plateNumberPic)){
							j++;
							String picpath = ctxPath+plateNumber;
							String numByPic = PictureIdentify.getNumByPic(picpath);
							if(StringUtils.isNotBlank(numByPic)){
								logger.info("配载单号：  OrderCode ——>  "+ order.getOrderCode()+"  , 车牌号识别后：PlateNumber ——>  "+numByPic );
								order.setPlateNumber(numByPic);
								z++;
							}
							order.setPlateNumberFlag("1");;//已处理
							int updateByPrimaryKey = roadFeeMapper.updateByPrimaryKeySelective(order);
							if(updateByPrimaryKey>0){
								logger.info("...更新成功");
								i++;
							}
						}
						
					}
				
			}
		}
		logger.info("     【pic-num ：job】                本次共查出（ "+selectNewOrder.size()+"）单  ， post到阿里{pic非空}("+j+")单,post阿里查询到("+z+")单， mysql共标记（ "+i+"）单           "  );
	}
}
